﻿using System;
using System.Collections.Generic;
using SharpSqlAnalyzer.nodes;
using SharpSqlAnalyzer.nodes.mssql;
using SharpSqlAnalyzer.nodes.oracle;

namespace SharpSqlAnalyzer.stmt
{
	// Token: 0x020000B4 RID: 180
	public class TMergeSqlStatement : TCustomSqlStatement
	{
		// Token: 0x17000104 RID: 260
		// (get) Token: 0x06000602 RID: 1538 RVA: 0x002FE0C7 File Offset: 0x002FC2C7
		// (set) Token: 0x06000603 RID: 1539 RVA: 0x002FE0CF File Offset: 0x002FC2CF
		public virtual TErrorLoggingClause ErrorLoggingClause
		{
			get
			{
				return this._errorLoggingClause;
			}
			set
			{
				this._errorLoggingClause = value;
			}
		}

		// Token: 0x17000105 RID: 261
		// (get) Token: 0x06000604 RID: 1540 RVA: 0x002FE0D8 File Offset: 0x002FC2D8
		// (set) Token: 0x06000605 RID: 1541 RVA: 0x002FE0E0 File Offset: 0x002FC2E0
		public virtual TOptionClause OptionClause
		{
			get
			{
				return this._optionClause;
			}
			set
			{
				this._optionClause = value;
			}
		}

		// Token: 0x06000606 RID: 1542 RVA: 0x002FE0E9 File Offset: 0x002FC2E9
		public TMergeSqlStatement(EDbVendor dbvendor) : base(dbvendor)
		{
			this.sqlstatementtype = ESqlStatementType.sstmerge;
		}

		// Token: 0x06000607 RID: 1543 RVA: 0x002FE0FA File Offset: 0x002FC2FA
		internal override void buildsql()
		{
		}

		// Token: 0x06000608 RID: 1544 RVA: 0x002FE0FC File Offset: 0x002FC2FC
		internal override void clear()
		{
		}

		// Token: 0x06000609 RID: 1545 RVA: 0x002FE0FE File Offset: 0x002FC2FE
		internal override string getasprettytext()
		{
			return "";
		}

		// Token: 0x0600060A RID: 1546 RVA: 0x002FE105 File Offset: 0x002FC305
		internal virtual void iterate(TVisitorAbs pvisitor)
		{
		}

		// Token: 0x17000106 RID: 262
		// (get) Token: 0x0600060B RID: 1547 RVA: 0x002FE107 File Offset: 0x002FC307
		// (set) Token: 0x0600060C RID: 1548 RVA: 0x002FE10F File Offset: 0x002FC30F
		public virtual TObjectNameList ColumnList
		{
			get
			{
				return this._columnList;
			}
			set
			{
				this._columnList = value;
			}
		}

		// Token: 0x17000107 RID: 263
		// (get) Token: 0x0600060D RID: 1549 RVA: 0x002FE118 File Offset: 0x002FC318
		// (set) Token: 0x0600060E RID: 1550 RVA: 0x002FE120 File Offset: 0x002FC320
		public virtual TExpression MatchedSearchCondition
		{
			get
			{
				return this._matchedSearchCondition;
			}
			set
			{
				this._matchedSearchCondition = value;
			}
		}

		// Token: 0x17000108 RID: 264
		// (get) Token: 0x0600060F RID: 1551 RVA: 0x002FE129 File Offset: 0x002FC329
		// (set) Token: 0x06000610 RID: 1552 RVA: 0x002FE131 File Offset: 0x002FC331
		public virtual TExpression NotMatchedSearchCondition
		{
			get
			{
				return this._notMatchedSearchCondition;
			}
			set
			{
				this._notMatchedSearchCondition = value;
			}
		}

		// Token: 0x17000109 RID: 265
		// (get) Token: 0x06000611 RID: 1553 RVA: 0x002FE13A File Offset: 0x002FC33A
		// (set) Token: 0x06000612 RID: 1554 RVA: 0x002FE142 File Offset: 0x002FC342
		public virtual TTable UsingTable
		{
			get
			{
				return this._usingTable;
			}
			set
			{
				this._usingTable = value;
			}
		}

		// Token: 0x1700010A RID: 266
		// (get) Token: 0x06000613 RID: 1555 RVA: 0x002FE14B File Offset: 0x002FC34B
		// (set) Token: 0x06000614 RID: 1556 RVA: 0x002FE153 File Offset: 0x002FC353
		public virtual TExpression Condition
		{
			get
			{
				return this._condition;
			}
			set
			{
				this._condition = value;
			}
		}

		// Token: 0x1700010B RID: 267
		// (get) Token: 0x06000615 RID: 1557 RVA: 0x002FE15C File Offset: 0x002FC35C
		// (set) Token: 0x06000616 RID: 1558 RVA: 0x002FE164 File Offset: 0x002FC364
		public virtual TMergeUpdateClause UpdateClause
		{
			get
			{
				return this._updateClause;
			}
			set
			{
				this._updateClause = value;
			}
		}

		// Token: 0x1700010C RID: 268
		// (get) Token: 0x06000617 RID: 1559 RVA: 0x002FE16D File Offset: 0x002FC36D
		// (set) Token: 0x06000618 RID: 1560 RVA: 0x002FE175 File Offset: 0x002FC375
		public virtual TMergeInsertClause InsertClause
		{
			get
			{
				return this._insertClause;
			}
			set
			{
				this._insertClause = value;
			}
		}

		// Token: 0x1700010D RID: 269
		// (get) Token: 0x06000619 RID: 1561 RVA: 0x002FE17E File Offset: 0x002FC37E
		// (set) Token: 0x0600061A RID: 1562 RVA: 0x002FE186 File Offset: 0x002FC386
		public virtual List<TMergeWhenClause> WhenClauses
		{
			get
			{
				return this._whenClauses;
			}
			set
			{
				this._whenClauses = value;
			}
		}

		// Token: 0x0600061B RID: 1563 RVA: 0x002FE190 File Offset: 0x002FC390
		public override int doParseStatement(TCustomSqlStatement psql)
		{
			if (this.rootNode == null)
			{
				return -1;
			}
			TMergeSqlNode tmergeSqlNode = (TMergeSqlNode)this.rootNode;
			base.doParseStatement(psql);
			base.scanOracleHint(tmergeSqlNode.startToken);
			if (tmergeSqlNode.cteList != null)
			{
				this.CteList = tmergeSqlNode.cteList;
				this.CteList.doParse(this, ESqlClause.cte);
			}
			TTable ttable = this.analyzeFromTable(tmergeSqlNode.TargetTable, new bool?(true));
			ttable.EffectType = ETableEffectType.tetMerge;
			this.TargetTable = ttable;
			this._usingTable = this.analyzeFromTable(tmergeSqlNode.UsingTable, new bool?(true));
			this._usingTable.EffectType = ETableEffectType.tetSelect;
			this._condition = tmergeSqlNode.Condition;
			this._condition.doParse(this, ESqlClause.joinCondition);
			if (tmergeSqlNode.ColumnList != null)
			{
				this._columnList = tmergeSqlNode.ColumnList;
				for (int i = 0; i < tmergeSqlNode.ColumnList.size(); i++)
				{
					TObjectName objectName = tmergeSqlNode.ColumnList.getObjectName(i);
					objectName.Location = ESqlClause.mergeInsert;
					this.TargetTable.ObjectNameReferences.addObjectName(objectName);
					this.TargetTable.LinkedColumns.addObjectName(objectName);
					objectName.SourceTable = this.TargetTable;
				}
			}
			this._whenClauses = tmergeSqlNode.WhenClauses;
			if (this._whenClauses != null)
			{
				foreach (TMergeWhenClause tmergeWhenClause in this._whenClauses)
				{
					tmergeWhenClause.doParse(this, ESqlClause.unknown);
				}
			}
			if (tmergeSqlNode.OutputClause != null)
			{
				tmergeSqlNode.OutputClause.doParse(this, ESqlClause.output);
				this.OutputClause = tmergeSqlNode.OutputClause;
			}
			this._optionClause = tmergeSqlNode.OptionClause;
			this._errorLoggingClause = tmergeSqlNode.ErrorLoggingClause;
			return 0;
		}

		// Token: 0x0600061C RID: 1564 RVA: 0x002FE34C File Offset: 0x002FC54C
		public override void accept(TParseTreeVisitor v)
		{
			v.preVisit(this);
			v.postVisit(this);
		}

		// Token: 0x0600061D RID: 1565 RVA: 0x002FE35C File Offset: 0x002FC55C
		public override void acceptChildren(TParseTreeVisitor v)
		{
			v.preVisit(this);
			this._usingTable.acceptChildren(v);
			this._condition.acceptChildren(v);
			if (this._columnList != null)
			{
				this._columnList.acceptChildren(v);
			}
			if (this._whenClauses != null)
			{
				foreach (TMergeWhenClause tmergeWhenClause in this._whenClauses)
				{
					tmergeWhenClause.acceptChildren(v);
				}
			}
			if (this.OutputClause != null)
			{
				this.OutputClause.acceptChildren(v);
			}
			if (this._errorLoggingClause != null)
			{
				this._errorLoggingClause.acceptChildren(v);
			}
			v.postVisit(this);
		}

		// Token: 0x04001177 RID: 4471
		private TErrorLoggingClause _errorLoggingClause;

		// Token: 0x04001178 RID: 4472
		private TOptionClause _optionClause;

		// Token: 0x04001179 RID: 4473
		private TExpression _matchedSearchCondition;

		// Token: 0x0400117A RID: 4474
		private TExpression _notMatchedSearchCondition;

		// Token: 0x0400117B RID: 4475
		private TObjectNameList _columnList;

		// Token: 0x0400117C RID: 4476
		private TTable _usingTable;

		// Token: 0x0400117D RID: 4477
		private TExpression _condition;

		// Token: 0x0400117E RID: 4478
		private TMergeUpdateClause _updateClause;

		// Token: 0x0400117F RID: 4479
		private TMergeInsertClause _insertClause;

		// Token: 0x04001180 RID: 4480
		private List<TMergeWhenClause> _whenClauses;
	}
}
